package com.zrc.superframe_net.room

import android.content.Context
import androidx.room.Room

/**
 * @Author: superman
 * @CreateTime: 10/15/21
 * @Describe:
 */
object NetRoomUtil {

    lateinit var database: NetDatabase

    fun init(context: Context, dbName: String) {
        database = Room.databaseBuilder(context, NetDatabase::class.java, dbName)
            .allowMainThreadQueries() //支持主线程
            .fallbackToDestructiveMigration()
            //.addMigrations(MIGRATION_1_2)//升级的时候用到  比如有添加数据库字段
            .build()
    }

//    val MIGRATION_1_2: Migration = object : Migration(2, 3) {
//        override fun migrate(database: SupportSQLiteDatabase) {
//            //1升级2的任务
//            database.execSQL(
//            "CREATE TABLE IF NOT EXISTS `Form` (`fromid` INTEGER, `downUserName` TEXT DEFAULT '', `downStstus` INTEGER NOT NULL DEFAULT 0, `inputStstus` INTEGER NOT NULL DEFAULT 0, `uploadStstus` INTEGER NOT NULL DEFAULT 0, `test` TEXT, `test1` TEXT, `id` TEXT, `formCode` TEXT, `maintTaskUid` TEXT, `maintObject` TEXT, `maintType` TEXT, `maintPlanFullname` TEXT, `conditionCode` TEXT, `periodCode` TEXT, `planDate` TEXT, `leadDate` TEXT, `lagDate` TEXT, `state` TEXT, `claimUser` TEXT, `claimTime` TEXT, `startUser` TEXT, `startTime` TEXT, `fillinComment` TEXT, `abnormal` INTEGER NOT NULL, `siteCode` TEXT, `tenantCode` TEXT, `createdBy` TEXT, `createdTimestamp` TEXT, `updatedBy` TEXT, `updatedTimestamp` TEXT, `maintRouteDescription` TEXT, `taskWorkingTime` TEXT, `formEquipments` TEXT, PRIMARY KEY(`fromid`))"
//            )//创建一张临时form表
//            database.execSQL("INSERT INTO temp_Form SELECT * FROM Form")//将旧数据拷贝到时form表中
//            database.execSQL("DROP TABLE Form")//删除旧表
//            database.execSQL("ALTER TABLE temp_Form RENAME TO Form")//将临时表表名重命名为Form
//        }
//    }
}